package com.umgsai.wx.backend.dd;

import com.google.common.collect.Maps;

import java.util.List;
import java.util.Map;

public class TwoSum {

    public static void main(String[] args) {
        int[] nums = new int[]{1, 2, 3, 4, 5, 6, 7, 8};
        int sum = 10;
        Map<Integer, Integer> map = Maps.newHashMap();

        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i], i);
        }

        for (int num : nums) {
            int target = sum - num;
            if (target == num) {
                continue;
            }
            if (map.containsKey(target)) {
                System.out.println(num + "+" + target + "=" + sum);
                map.remove(target);
                map.remove(num);
            }
        }
    }

}
